package com.zp.mvppractice.io;



import com.zp.mvppractice.beans.ResponseBean;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


/**
 * Created by izp on 2017/6/2.
 */

public abstract class ResultObserver<T> implements Observer<ResponseBean<T>> {
    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(ResponseBean<T> tResponseBean) {
        if (null==tResponseBean || null==tResponseBean.getHead() || null==tResponseBean.getBody()){
            onError(new Throwable("数据解析错误"));
            return;
        }
        if (tResponseBean.getHead().getResult()<0){
            onError(new Throwable("失败"+tResponseBean.getHead().getMsg()));
            return;
        }
        if (tResponseBean.getHead().getID() ==1){
            onError(new Throwable("登陆过期，请重新登陆"));
            return;
        }
        onResultNext(tResponseBean);
    }


    public abstract void onResultNext(ResponseBean<T> responseBean);


}
